package lab_12.com.acme.bankapp.domain.bank;


public class SavingsAccount extends AbstractAccount {

	public SavingsAccount(double balance) {
		super(balance);
	}

	@Override
	public void withdraw(double amount) throws IllegalArgumentException {
		if (amount > 0) {
			balance -= amount;
		} else {
			throw new IllegalArgumentException();
		}
	}

	@Override
	public double maximumAmountToWithdraw() {
		return (balance >= 0) ? balance : 0;
	}
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("---Savings account---\n");
		builder.append(String.format("Account id: %1$d\n", getId()));
		builder.append(String.format("Balance: %1$f\n", balance));
		builder.append(String.format("Balance decimal value: %1$d\n", decimalValue()));
		builder.append(String.format("Maximum amount to withdraw: %1$f\n",
				maximumAmountToWithdraw()));
			
		return builder.toString();
	}

	@Override
	public void printAllAccountData() {
		System.out.print(toString());
	}
	
	
}
